
public class Tunnels {
	char[][] board;
	boolean[][] tunnels;
	
	Tunnels(char[][] matrixIn){
		board = matrixIn;
		tunnels = new boolean[matrixIn.length][matrixIn[0].length];
	}
	
	public boolean[][] getTunnels(){
		
		//LETAR EFTER HORISONTELLA TUNNLAR
		for(int row=1;row<board.length-1;row++){						//BÖRJAR EN RAD NERÅT SÅ INTE OUT OF BOUNDS
			for(int col=1;col<board[0].length-3;col++){					//KOLLA SÅ DE BLIR RETT MED RADER Å KOLUIMNEr
				if(isPotentialXTunnel(row,col) && isOpen(row,col-1)){
					if(isPotentialXTunnel(row,col+1)){
						if(isPotentialXTunnel(row,col+2)){
							if(isOpen(row,col+3)){
								if(tunnels[row][col] == false){
								tunnels[row][col] = true;
								}
								if(tunnels[row][col+1] == false){
									tunnels[row][col+1] = true;
								}
								if(tunnels[row][col+2] == false){
									tunnels[row][col+2] = true;
								}
							}
						}
					}
				}
			}
		}
		
		//LETAR EFTER VERTIKALA TUNNLAR
				for(int row=1;row<board.length-3;row++){						//BÖRJAR EN RAD NERÅT SÅ INTE OUT OF BOUNDS
					for(int col=1;col<board[0].length-1;col++){					//KOLLA SÅ DE BLIR RETT MED RADER Å KOLUIMNEr
						if(isPotentialYTunnel(row,col) && isOpen(row-1,col)){
							if(isPotentialYTunnel(row+1,col)){
								if(isPotentialYTunnel(row+2,col)){
									if(isOpen(row+3,col)){
										if(tunnels[row][col] == false){
										tunnels[row][col] = true;
										}
										if(tunnels[row+1][col] == false){
											tunnels[row+1][col] = true;
										}
										if(tunnels[row+2][col] == false){
											tunnels[row+2][col] = true;
										}
									}
								}
							}
						}
					}
				}
		
		return tunnels;
	}
	
	
	// DOM KOLLAR BARA PÅ VEGGAR OCH MARK, INTE GOALS Å PLAYER Å PLAYER ON GOALS N SHIT
	public boolean isPotentialXTunnel(int row, int col){
		if(		board[row-1][col]=='#'
				&& 
				(board[row][col]!='#' && board[row][col-1]!='#' && board[row][col+1]!='#')
				&&
				board[row+1][col]=='#'){
			return true;
		}
		return false;
	}
	
	public boolean isPotentialYTunnel(int row, int col){
		if(		board[row][col-1]=='#'
				&&
				(board[row][col]!='#' && board[row-1][col]!='#' && board[row][col]!='#')
				&&
				board[row][col+1]=='#'){
			return true;
		}
		return false;
	}
	
	public boolean isOpen(int row, int col){
		if(board[row][col] != '#'){
			return true;
		}
		return false;
	}
}
